package com.bckj.fastboot.core.mybatisplus.configuration;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.bckj.fastboot.core.mybatisplus.FastSqlInjector;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

/**
 * @author wfc
 */
@AutoConfiguration
@MapperScan("com.bckj.fastboot.core.mybatisplus.mapper")
public class FastMybatisPlusConfiguration {

    /**
     * 默认使用这些mp拦截器 分页 + 乐观锁
     */
    @Bean
    @ConditionalOnMissingBean(MybatisPlusInterceptor.class)
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
//        mybatisPlusInterceptor.addInnerInterceptor(new DataPermissionInterceptor(new MyDataScopeHandler()));
        return mybatisPlusInterceptor;
    }

    @Bean
    public FastSqlInjector fastSqlInjector() {
        return new FastSqlInjector();
    }

}
